package com.example.test.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

/**
 * Created by lsl on 2021/3/5.
 */
@Configuration
@EnableResourceServer
public class ResourcesServerConfig extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/doc.html").permitAll()
                .antMatchers("/actuator/**").permitAll()
                .antMatchers("/swagger-resources/**").permitAll()
                .antMatchers("/swagger-ui.html").permitAll()
                .antMatchers("/*/api-docs").permitAll()
                .antMatchers("/webjars/**").permitAll()
                .anyRequest().authenticated()
                // 关闭跨域
                .and().csrf().disable();
//                .requireCsrfProtectionMatcher(AnyRequestMatcher.INSTANCE)
        // 开启基于cookie的csrf保护
//                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
        // 开启http basic支持
//                .and().httpBasic();
    }

}
